#pragma once

#include <gofcl_dma_int.h>

typedef struct {
	u32_s channel_0_interrupt : 1;
	u32_s channel_0_full_finish : 1;
	u32_s channel_0_half_finish : 1;
	u32_s channel_0_error : 1;

	u32_s channel_1_interrupt : 1;
	u32_s channel_1_full_finish : 1;
	u32_s channel_1_half_finish : 1;
	u32_s channel_1_error : 1;

	u32_s channel_2_interrupt : 1;
	u32_s channel_2_full_finish : 1;
	u32_s channel_2_half_finish : 1;
	u32_s channel_2_error : 1;

	u32_s channel_3_interrupt : 1;
	u32_s channel_3_full_finish : 1;
	u32_s channel_3_half_finish : 1;
	u32_s channel_3_error : 1;

	u32_s channel_4_interrupt : 1;
	u32_s channel_4_full_finish : 1;
	u32_s channel_4_half_finish : 1;
	u32_s channel_4_error : 1;

	u32_s channel_5_interrupt : 1;
	u32_s channel_5_full_finish : 1;
	u32_s channel_5_half_finish : 1;
	u32_s channel_5_error : 1;

	u32_s channel_6_interrupt : 1;
	u32_s channel_6_full_finish : 1;
	u32_s channel_6_half_finish : 1;
	u32_s channel_6_error : 1;

	u32_s : 4;
} dma_int_expl_s;

_Static_assert(sizeof(dma_int_expl_s) == 4,
	       "Struct dma_int_expl_s defined error!");

static inline dma_int_expl_s dma_get_interrupt(dma_qe dma_q) {
	union {
		dma_int_expl_s e;
		dma_int_s i;
	} ei = {
		.i = dma_rreg_intf_s(dma_q),
	};
	return ei.e;
}

static inline void dma_clear_interrupt(dma_qe dma_q, dma_int_expl_s intc) {
	union {
		dma_int_expl_s e;
		dma_int_s i;
	} ei = {
		.e = intc,
	};
	dma_wreg_intc_s(dma_q, ei.i);
}
